#include "Types.h"
#include <cmath>


Vector2 Vector2::operator-( const Vector2& other )
{
	return Vector2(x - other.x, y - other.y);
}

Vector2 Vector2::operator+( const Vector2& other )
{
	return Vector2(x + other.x, y + other.y);
}

Vector2 operator*( const Vector2& vector, float scalar )
{
	return Vector2(vector.x * scalar, vector.y * scalar);
}

float Vector2::lengthSq() const
{
	return (x * x + y * y);
}

float Vector2::length() const
{
	return sqrt(x * x + y * y);
}

Vector2 Vector2::normalized() const
{
	float l = length();
	if (l == 0.0f)
		return Vector2(0.0f, 0.0f);

	return Vector2(x / l, y / l);
}
